﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace FtpWorkerRole.FtpServer
{
    class Utils
    {
        public static bool sendMessage(TcpClient socket, String message)
        {
            bool flag = true;
            try
            {
                NetworkStream networkStream = socket.GetStream();
                byte[] messageByte = System.Text.Encoding.ASCII.GetBytes(message.ToCharArray());
                networkStream.Write(messageByte, 0, messageByte.Length);
                networkStream.Flush();
            }
            catch (Exception)
            {
                flag = false;
            }

            return flag;
        }
        public static bool sendData(TcpClient socket, byte[] data, int length)
        {
            bool flag = false;
            try
            {
                var stream = socket.GetStream();
                stream.Write(data, 0, length);
                stream.Flush();
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }
        public static bool sendData(TcpClient socket, byte[] data)
        {
            return sendData(socket, data, data.Length);
        }
        public static string getUriName(Uri uri)
        {
            var s = uri.ToString();
            int idx = s.LastIndexOf(@"/");

            return s.Substring(idx + 1);
        }
        public static string getMonth(int month)
        {
            switch (month)
            {
                case 1:
                    return "Jan";
                case 2:
                    return "Feb";
                case 3:
                    return "Mar";
                case 4:
                    return "Apr";
                case 5:
                    return "May";
                case 6:
                    return "Jun";
                case 7:
                    return "Jul";
                case 8:
                    return "Aug";
                case 9:
                    return "Sep";
                case 10:
                    return "Oct";
                case 11:
                    return "Nov";
                case 12:
                    return "Dec";
                default:
                    return "";
            }

        }
    }
}
